<?php

namespace App\Services\Server\Tencent\TencentCloud;

use App\Helpers\FileHelper;
use App\Services\Server\Tencent\BaseTencentService;
use Exception;

class TencentCloudService extends BaseTencentService
{

    /**
     * 上传文件
     *
     * @param array $params
     * @return array
     * @throws Exception
     */
    public function uploadFile(array $params): array
    {
        $result = $this->getTencentCloudLibrary()->uploadFile($params);

        return [
            'fullPath' => isset($result['Key']) ? FileHelper::getCompleteUrl($result['Key']) : '',
            'path'     => $result['Key'] ?? '',
        ];
    }

    /**
     * 获取临时密钥
     *
     * @throws Exception
     */
    public function getUploadToken(array $params): array
    {
        return $this->getTencentCloudLibrary()->getUploadToken($params['pathPrefix']);
    }

}
